package com.itheima.d2_math;

/**
 * 常用的api：math类
 */
public class MathDemo {
    public static void main(String[] args) {
        //绝对值
        System.out.println(Math.abs(-10));
        System.out.println(Math.abs(10));


        //向上取整
        System.out.println(Math.ceil(10.1));
        System.out.println(Math.ceil(-10.9));

        //向下取整
        System.out.println(Math.floor(10.1));
        System.out.println(Math.floor(-10.9));

        //四舍五入
        System.out.println(Math.round(10.1));
        System.out.println(Math.round(10.5));

        //取较大值
        System.out.println(Math.max(10, 20));
        System.out.println(Math.max(10.1, 20.1));
        //取较小值
        System.out.println(Math.min(10, 20));
        System.out.println(Math.min(10.1, 20.1));

        //取次幂
        System.out.println(Math.pow(2, 3));
        System.out.println(Math.pow(3, 3));

        //取随机数
        System.out.println(Math.random());//[0,1) 包前不包后
        System.out.println( (int)(Math.random()*10)+1);// [1,10]
    }
}
